<?php

namespace App\Providers;


use Illuminate\Auth\EloquentUserProvider;
use Illuminate\Contracts\Hashing\Hasher as HasherContract;

class MyEloquentProvider extends EloquentUserProvider
{

    /**
     * Create a new database user provider.
     *
     * @param  \Illuminate\Contracts\Hashing\Hasher  $hasher
     * @param  string  $model
     * @return void
     */
    public function __construct(HasherContract $hasher, $model)
    {
        parent::__construct($hasher, $model);
    }

    public function retrieveById($identifier)
    {
        $model = $this->createModel();
        $cache_key = $model->getMorphClass() . ":" . $identifier;
        return \Cache::remember($cache_key, 3600, function () use($identifier, $model){
            return $this->newModelQuery($model)
                ->where($model->getAuthIdentifierName(), $identifier)
                ->first();
        });
    }
}
